﻿using System;
using System.Collections.Generic;
using Autodesk.Revit.DB;
using YJKInspectModelFunc;
using YJKInspectModelFunc.ModelLayer;

namespace YJKSparseDistance.ModelLayer
{
	public class AreaPacker_EvacuationDistance : BaseAreaPacker
	{
		public List<RoomPacker_EvacuationDistance> LstAllRunWayRoom
		{
			get
			{
				return this.m_lstAllRunWayRoom;
			}
			set
			{
				this.m_lstAllRunWayRoom = value;
			}
		}

		public bool IfIsEvacuation
		{
			get
			{
				return this.m_bIfIsEvacuation;
			}
			private set
			{
				this.m_bIfIsEvacuation = value;
			}
		}

		public bool IfSparay
		{
			get
			{
				return this.m_IfSparay;
			}
		}

		public AreaPacker_EvacuationDistance(Area inputElement, RevitLinkInstance useRevitLinkInstance = null, object[] otherValues = null) : base(inputElement, useRevitLinkInstance, otherValues)
		{
		}

		public override void AddCloseCurveAnalaysPacker(ICloseCurveAnalays inputValue)
		{
			base.AddCloseCurveAnalaysPacker(inputValue);
			Utility.AddFrontRoomStairIdInList(inputValue, ref this.m_lstStairsIdForFrontRoom);
		}

		public override void AddRoomPacker(BaseRoomPacker inputValue)
		{
			base.AddRoomPacker(inputValue);
			if (inputValue is RoomPacker_EvacuationDistance && inputValue is RoomPacker_EvacuationDistance)
			{
				(inputValue as RoomPacker_EvacuationDistance).ParentAreaPacker = this;
			}
		}

		public void PrePareThisArea()
		{
			this.m_IfSparay = this.FindAreaSparay();
			this.SetStairRoom();
			this.SetRunWayRoom();
			this.SetEvacuationCondition();
		}

		private bool FindAreaSparay()
		{
			bool flag = false;
			double num = 0.0;
            return YJKInspectModelFunc.Utility.TryReadAreaOtherData(base.ThisArea, out flag, out num) && flag;
		}

		private void SetStairRoom()
		{
			this.m_lstAllStairsRoom = Utility.FindAllStairRooms(base.LstRoomPackerInThis, this.m_lstStairsIdForFrontRoom);
		}

		private void SetRunWayRoom()
		{
			this.m_lstAllRunWayRoom = Utility.FindAllRunWayRooms(this.m_lstAllStairsRoom, base.LstCloseCurvePackerInThis, base.LstRoomPackerInThis, true);
		}

		private void SetEvacuationCondition()
		{
			List<List<BaseDoorPacker>> list = new List<List<BaseDoorPacker>>();
			bool flag = false;
			bool flag2 = true;
			foreach (RoomPacker_EvacuationDistance roomPacker_EvacuationDistance in this.m_lstAllRunWayRoom)
			{
				list.AddRange(roomPacker_EvacuationDistance.AllOutSideDoor);
			}
			foreach (RoomPacker_EvacuationDistance roomPacker_EvacuationDistance2 in this.m_lstAllStairsRoom)
			{
				if (roomPacker_EvacuationDistance2.ThisKindEnum == StairRoomKindEnum.Open)
				{
					flag = true;
				}
				flag2 = (flag2 && roomPacker_EvacuationDistance2.IfStrairsRoomDoorToOutSide);
			}
			if (flag && list.Count > 0)
			{
				this.IfIsEvacuation = true;
				return;
			}
			if (list.Count < 2 && !flag2)
			{
				this.IfIsEvacuation = false;
				return;
			}
			if (list.Count >= 2 && flag2)
			{
				this.IfIsEvacuation = true;
				return;
			}
			this.IfIsEvacuation = false;
		}

		private List<RoomPacker_EvacuationDistance> FindRunWayRoom(RoomPacker_EvacuationDistance input)
		{
			return Utility.FindRunWayRoom(input);
		}

		private List<RoomPacker_EvacuationDistance> FindRunWayRoom(ICloseCurveAnalays input)
		{
			return Utility.FindRunWayRoom(input);
		}

		private List<int> m_lstStairsIdForFrontRoom = new List<int>();

		private List<RoomPacker_EvacuationDistance> m_lstAllStairsRoom = new List<RoomPacker_EvacuationDistance>();

		private List<RoomPacker_EvacuationDistance> m_lstAllRunWayRoom = new List<RoomPacker_EvacuationDistance>();

		private bool m_bIfIsEvacuation;

		private bool m_IfSparay;
	}
}
